package com.designpattern.strategy;

/**
 * 项目名称: java_algorithm
 * @ClassName CalStrategyTest
 * @Description
 * @Author huipanxing huipanxing@chinasofti.com   @Date 2021/9/10 9:12
 */
public class CalStrategyTest {
    public static void main(String[] args) {
        StrategyCal strategyCal=new StrategyCal(new AddCal());
        int result = strategyCal.cal(3, 1);
        System.out.println(result);

        StrategyCal strategyCal1=new StrategyCal(new PlusCal());
        int result1 = strategyCal1.cal(3, 1);
        System.out.println(result1);
    }
}

class StrategyCal{
    private Cal cal;

    public StrategyCal(Cal cal) {
        this.cal = cal;
    }
    public int cal(int a,int b){
        return cal.cal(a,b);
    }
}

interface Cal {
    int cal(int a, int b);
}

class AddCal implements Cal {

    @Override
    public int cal(int a, int b) {
        return a + b;
    }
}

class PlusCal implements Cal {

    @Override
    public int cal(int a, int b) {
        return a - b;
    }
}
